import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:library_base/res/colors.dart';
import 'package:library_base/utils/sp_util.dart';
import 'package:library_base/res/app_theme.dart';

class ThemeUtil {
  static void changeTheme(ThemeType themeMode) {
    SPUtil.putString(SPUtil.key_theme, themeMode.name);
    Get.changeTheme(getTheme());
  }

  static ThemeData getTheme() {
    final String theme = SPUtil.getString(SPUtil.key_theme, defValue: ThemeType.green.name);
    if (theme == ThemeType.green.name) {
      return greenTheme;
    } else if (theme == ThemeType.dark.name) {
      return dartTheme;
    } else {
      return greenTheme;
    }
  }

  static ThemeMode getThemeMode() {
    final String theme = SPUtil.getString(SPUtil.key_mode, defValue: 'light');
    switch (theme) {
      case 'dark':
        return ThemeMode.dark;
      case 'light':
        return ThemeMode.light;
      default:
        return ThemeMode.system;
    }
  }
}

extension ColorSchemeExt on ColorScheme {
  Color pressColor() {
    final String theme = SPUtil.getString(SPUtil.key_theme, defValue: ThemeType.green.name);
    if (theme == ThemeType.green.name) {
      return Colours.red;
    } else if (theme == ThemeType.dark.name) {
      return Colours.red;
    } else {
      return Colours.red;
    }
  }
}

enum ThemeType {
  green,
  dark,
}
